// 分类相关API封装
import request from './request'

// 获取分类树
export const getCategoryTree = () => {
  return request({
    url: '/category/tree',
    method: 'get'
  })
}

// 获取所有分类树（包含禁用的）
export const getAllCategoryTree = () => {
  return request({
    url: '/category/all',
    method: 'get'
  })
}

// 根据ID获取分类
export const getCategoryById = (id) => {
  return request({
    url: `/category/${id}`,
    method: 'get'
  })
}

// 根据父ID获取子分类
export const getCategoriesByParentId = (parentId) => {
  return request({
    url: `/category/children/${parentId}`,
    method: 'get'
  })
}

// 根据级别获取分类
export const getCategoriesByLevel = (level) => {
  return request({
    url: `/category/level/${level}`,
    method: 'get'
  })
}
// 新增分类
export const addCategory = (data) => {
  return request({
    url: '/admin/category',
    method: 'post',
    data
  })
}

// 更新分类
export const updateCategory = (id, data) => {
  return request({
    url: `/admin/category/${id}`,
    method: 'put',
    data
  })
}

// 删除分类
export const deleteCategory = (id) => {
  return request({
    url: `/admin/category/${id}`,
    method: 'delete'
  })
}